#include <stdio.h>

int val[17] = \
	{7, 9, 10, 5, 8, 4, 2, 1, \
	6, 3, 7, 9, 10, 5, 8, 4, 2};

char cal[11] = \
	{'1', '0', 'X', '9', '8', \
	'7', '6', '5', '4', '3', '2'};

int main(int argc, int argv)
{
	int i = 0;
	int sum = 0;
	int cycle = 0;

	char input[19] = {0};

	int mark = 0, mark1 = 0;

	scanf("%d", &cycle);

	while(cycle--)
	{
		scanf("%s", input);

		sum = 0;
		mark1 = 0;

		for(i = 0; i < 17; i++)
		{
			if(input[i] > '9' && input[i] < '0')
			{
				mark++;
				mark1++;
				printf("%s\n", input);
				break;
			}
			else
			{
				sum += (input[i] - '0') * val[i];
			}
		}

		if(cal[sum % 11] != input[17] && (!mark1))
		{
			mark++;
			printf("%s\n", input);
		}
	}


	if(!mark)
	{
		printf("All passed\n");
	}

	return 0;
}
